package com.dream.wuliu.view;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.WindowFeature;

import android.widget.TextView;

import com.actionbarsherlock.view.Window;
import com.beardedhen.androidbootstrap.BootstrapButton;
import com.dream.vo.api.ApiOrderDetail;
import com.dream.vo.api.ApiResult;
import com.dream.wuliu.service.OrderService;
import com.dream.wuliu.service.ServiceFactory;
import com.dream.wuliu.utils.GsonHelper;
import com.dream.wuliu.utils.MyUtils;
@EActivity(R.layout.order_detail)
@WindowFeature({(int)Window.FEATURE_INDETERMINATE_PROGRESS })
public class OrderDetailActivity extends BaseActivity {
	
	@Extra("id")
	Long id;
	
	@ViewById(R.id.tvCusName)
	TextView tvCusName;
	
	@ViewById(R.id.tvCusMobile)
	TextView tvCusMobile;
	
	@ViewById(R.id.tvFirstOrg)
	TextView tvFirstOrg;
	
	@ViewById(R.id.tvSecondOrg)
	TextView tvSecondOrg;
	
	@ViewById(R.id.tvCusType)
	TextView tvCusType;
	
	@ViewById(R.id.tvPhone)
	TextView tvPhone;
	
	@ViewById(R.id.tvAddress)
	TextView tvAddress;
	
	@ViewById(R.id.tvProMandatoryNo)
	TextView tvProMandatoryNo;
	
	@ViewById(R.id.tvProName)
	TextView tvProName;
	
	@ViewById(R.id.tvProPuchaseDate)
	TextView tvProPuchaseDate;
	
	@ViewById(R.id.tvProPurchasePrice)
	TextView tvProPurchasePrice;
	
	@ViewById(R.id.tvProRecepitNo)
	TextView tvProRecepitNo;
	
	@ViewById(R.id.tvProSalesContact)
	TextView tvProSalesContact;
	
	@ViewById(R.id.tvProSalesShop)
	TextView tvProSalesShop;
	
	@ViewById(R.id.tvProFirstCat)
	TextView tvProFirstCat;
	
	@ViewById(R.id.tvProSecondCat)
	TextView tvSecondCat;
	
	@ViewById(R.id.tvProBarcode)
	TextView tvProBarcode;
	
	@ViewById(R.id.btnFixOrder)
	BootstrapButton btnFixOrder;
	
    @AfterViews  
    public void init(){  
    	showProgress();
    	getDetail();
    }  
    
    @Background
	public void getDetail(){
    	gsonDetail  = new ServiceFactory.OrderServiceHelper() {
			@Override
			public ApiResult doService(OrderService service) {
				return service.detail(id);
			}
		}.execute(this);
    	showDetail();
		
	}
    
    private String gsonDetail;
    
    @UiThread
    public void showDetail(){
    	hideProgress();
    	ApiOrderDetail detail = GsonHelper.orderDetail(gsonDetail);
    	if(detail == null){return;}
    	
    	tvCusName.setText(detail.getCusName());
    	tvCusMobile.setText(detail.getCusMobile());
    	tvFirstOrg.setText(detail.getCusFirstOrg());
    	tvSecondOrg.setText(detail.getCusSecondOrg());
    	tvCusType.setText(detail.getCusType());
    	tvPhone.setText(detail.getCusPhone());
    	tvAddress.setText(detail.getCusAddress());
    	
    	this.tvProBarcode.setText(detail.getProBarcode());
    	this.tvProFirstCat.setText(detail.getProFirstCat());
    	this.tvProMandatoryNo.setText(detail.getProMandatoryNo());
    	this.tvProName.setText(detail.getProName());
    	this.tvProPuchaseDate.setText(detail.getProPurchaseDate());
    	this.tvProPurchasePrice.setText(detail.getProPurchasePrice());
    	this.tvProRecepitNo.setText(detail.getProRecepitNo());
    	this.tvProSalesContact.setText(detail.getProSalesContact());
    	this.tvProSalesShop.setText(detail.getProSalesShop());
    	this.tvSecondCat.setText(detail.getProSecondCat());
    }
    
    @Click(R.id.btnFixOrder)
    void fixOrderClick(){
    	if(MyUtils.isNotBlank(gsonDetail)){
    		OrderUpdateActivity_.intent(this).detail(gsonDetail).start();
    	}
    }

}

